/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-05-19
 * Time: 21:31
 */
public class test1 {
    public static String compress_string (String s) {
        // write code here
        if(s==null || s.length()==0){
            return s;
        }
        StringBuilder sb = new StringBuilder();
        char ch = s.charAt(0);
        int count = 1;
        for(int i = 1;i<s.length();i++){
            char c = s.charAt(i);
            if(c==ch){
                count++;
            }else{
                sb.append(ch).append(count);
                ch = c;
                count = 1;
            }
            if(i==s.length()-1){
                sb.append(ch).append(count);
            }
        }
        // System.out.println("1");
        return sb.length()<s.length()?sb.toString():s;
    }

    public static void main(String[] args) {
        String str = compress_string("aabccccc");
        System.out.println(str);
    }
}
